<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
// 
//  messageborad.php
//  www.6block.com
//  
//  Created by Will_Lee on 2011-06-11.
//  Copyright 2011 lishuzu. All rights reserved.
// 
/*
*用户反馈留言板
*/
class Messageboard extends CI_Controller {

	public function	__construct(){
		parent::__construct();
		$this->load->model('messageboard_model', 'msg');
 		$this->load->model('common/security_model');
		$this->userinfo = $this->session->userdata('userinfo') ? $this->session->userdata('userinfo') : '';
	}
	
	public function index()
	{
		$data = $this->msg->get_msgs_page();
		$data['userinfo'] = $this->userinfo;
		$this->load->template('messageboard_tpl',$data);
	}
	
	function add_msg(){
		$username = $this->input->post('username') ? trim($this->input->post('username', true)) : '';
		$email = $this->input->post('email') ? trim($this->input->post('email', true)) : '';
		$msg = $this->input->post('msg') ? trim($this->input->post('msg', true)) : '';
		$isanonymous = $this->input->post('isanonymous') ? trim($this->input->post('isanonymous', true)) : 0;
		if ($email && $msg) {
			$insertdata = array(
				'username' => $username,
				'email' => $email,
				'content' => $msg,
				'dateline' => now(),
				'status' => '1'
				);
			if ($this->userinfo['avatar']) {
				$insertdata['avatar'] = $this->userinfo['avatar'];
				$insertdata['uid'] = $this->userinfo['uid'];
				if (intval($isanonymous) == '1') {
					$insertdata['status'] = '1';
				}else{
					$insertdata['status'] = '0';					
				}
				//更新用户email
				$updatedata = array(
					'email' => $email
					);
				$this->db->where('uid', $this->userinfo['uid']);
				$this->db->update('user', $updatedata);
				$this->security_model->update_user_session();
			}
			$id = $this->msg->insert_msg($insertdata);
			if ($id) {
				
				showjsonmessage('操作成功', '1', array('mid' => $id));
			}else{
				showjsonmessage('操作失败', '3');
			}
		}
		showjsonmessage('请填写必要信息', '2');
	}
	
	function get_msgs(){
		$data = $this->msg->get_msgs_page();
		$this->load->template('msg_list_tpl',$data);
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/messageborad.php */